<?php
/**
 * 网站程序的入口调用对象
 * @author Ronnie
 * @copyright Comdeng@gmail.com
 * @link http://comdeng.com/blog/
 * @version Version 0.1
 */
class Simpple_Application {
	private $rootPath;
	private static $app;
	
	private function __construct(){
		
	}
	
	/**
	 * 获取应用实例
	 *
	 * @return Simpple_Application
	 */
	public static function getInstance() {
		if (!self::$app) {
			self::$app = new Simpple_Application();
		}
		return self::$app;
	}
	
	/**
	 * 设置网站根目录
	 *
	 * @param string $path
	 */
	public function setRootPath($path) {
		$this->rootPath = $path;
	}
	
	/**
	 * 设置时区
	 *
	 * @param string $timezone
	 */
	public function initTimezone($timezone='Asia/Shanghai') {
		date_default_timezone_set($timezone);
	}
	
	/**
	 * 初始化编码
	 *
	 * @param string $charset
	 */
	public function initCharset($charset='UTF-8') {
		mb_internal_encoding($charset);
	}
	
	/**
	 * 初始化post的数据
	 */
	public function initPostData() {
		if (!empty($_POST)) {
			if (get_magic_quotes_gpc() && !empty($_POST)) {
				self::stripslashes_deep($_POST);
			}
		}
	}
	
	/**
	 * 增加包含路径
	 *
	 * @param string | array $paths
	 */
	public function addIncludePath($paths) {
		if (!is_array($paths)) {
			$paths = array($paths);
		}
		array_push($paths, get_include_path());
		set_include_path(implode(PATH_SEPARATOR, $paths));
	}
	
	
	/**
	 * 自动载入类
	 *
	 */
	public function autoLoad() {
		require_once 'AutoLoader.php';
		Simpple_AutoLoader::run();
	}
	
	/**
	 * 初始化日志器
	 *
	 * @param string $logDir
	 */
	public function initLogger($logDir) {
		require_once 'Logger.php';
		Simpple_Logger::setLoggerDir($logDir);
	}
	
	/**
	 * 分配
	 *
	 * @param string $path
	 * @param Simpple_Dispatcher $dispatcher
	 */
	public function dispatch($path, $dispatcher=null) {
		if ($dispatcher == null) {
			$dispatcher = Simpple_Dispatcher::getInstance();
		}
		$dispatcher->handler($path);
	}
	
	/**
	 * stripslasheds
	 *
	 * @param unknown_type $value
	 * @return unknown
	 */
	public static function stripslashes_deep(&$value) {
		$value = is_array($value) ?
		array_map('Simpple_Application::stripslashes_deep', $value) :
		stripslashes($value);
		return $value;
	}
	
	public function run() {
		
	}
}
